package com.ruoyi.house.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house.domain.vo.TbApartmentVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.TbApartment;
import com.ruoyi.house.service.ITbApartmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公寓管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/house/apartment")
public class TbApartmentController extends BaseController
{
    @Autowired
    private ITbApartmentService tbApartmentService;

    /**
     * 查询公寓管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbApartment tbApartment)
    {
        startPage();
//        List<TbApartment> list = tbApartmentService.selectTbApartmentList(tbApartment);
        List<TbApartmentVo> list = tbApartmentService.selectTbApartmentVoList(tbApartment);
        return getDataTable(list);
    }

    /**
     * 导出公寓管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:export')")
    @Log(title = "公寓管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbApartment tbApartment)
    {
        List<TbApartment> list = tbApartmentService.selectTbApartmentList(tbApartment);
        ExcelUtil<TbApartment> util = new ExcelUtil<TbApartment>(TbApartment.class);
        util.exportExcel(response, list, "公寓管理数据");
    }

    /**
     * 获取公寓管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:query')")
    @GetMapping(value = "/{apartmentId}")
    public AjaxResult getInfo(@PathVariable("apartmentId") Long apartmentId)
    {
        return success(tbApartmentService.selectTbApartmentByApartmentId(apartmentId));
    }

    /**
     * 新增公寓管理
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:add')")
    @Log(title = "公寓管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbApartment tbApartment)
    {
        return toAjax(tbApartmentService.insertTbApartment(tbApartment));
    }

    /**
     * 修改公寓管理
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:edit')")
    @Log(title = "公寓管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbApartment tbApartment)
    {
        return toAjax(tbApartmentService.updateTbApartment(tbApartment));
    }

    /**
     * 删除公寓管理
     */
    @PreAuthorize("@ss.hasPermi('house:apartment:remove')")
    @Log(title = "公寓管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{apartmentIds}")
    public AjaxResult remove(@PathVariable Long[] apartmentIds)
    {
        return toAjax(tbApartmentService.deleteTbApartmentByApartmentIds(apartmentIds));
    }
}
